<?
	include("../includes/config.php");
	include("../includes/login.php");
	include("../includes/functions.php");
	if(@$_GET['id_factura']){
		$id_fact = $_GET['id_factura'];
		$res = mysql_query("select * from facturi where id = '$id_fact' ");
		
	}
	if(@$_GET['exFurnizor']){
		$exfurnizor = $_GET['exFurnizor'];
	}
	if(@$_GET['exClient']){
		$exfurnizor = $_GET['exClient'];
	}
	if(@$_GET['incasare']){
		mysql_query("update facturi set status_factura = 'incheiata' where id =  '$id_fact'  ");
		
	}

 	
?>


<html>
	<head>
		<link rel="stylesheet" href="print.css" type="text/css" media="print" />
		<link rel="stylesheet" href="factura.css" type="text/css" />

	</head>
	
	<body>
		<div id="butonprint">
			<input class="noprint buton" type="button" onclick="javascript:window.print()" value="Printeaza">
		</div>
		<div id="main">
			<?
					$row = mysql_fetch_array($res);
			?>
			<div id="nr_comanda"><b>Factura</b></div>
			<div id="serie_factura"><b>Seria&nbsp; <? echo $row['serie']; ?>&nbsp; &nbsp; &nbsp; Nr:<? echo $row['numar']; ?>  </b></div>
			<div id="dataFactura">Data <? echo $row['data']; ?></div>
			<div id="dataFactura">data livrarii <? echo $row['data_livrari']; ?></div>
			<div class="facturaEx">ex.<? echo $exfurnizor; ?></div>
			
		<div id="factura_detalii">
			<div id="left"> 
				<table>
						<tr>
							<td>Unitate</td>
							<td><? echo $row['unitate']; ?></td>
						</tr>
						<tr>
							<td>Nr.Ord.R.c</td>
							<td><? echo $row['nr_ord_rc']; ?></td>
						</tr>
						<tr>
							<td>Cod fiscal</td>
							<td><? echo $row['cod_fiscal']; ?></td>
						</tr>
						<tr>
							<td>Sediul</td>
							<td><? echo $row['sediu']; ?></td>
						</tr>
						<tr>
							<td>Punct de lucru</td>
							<td><? echo $row['punct_lucru']; ?></td>
						</tr>
						<tr>
							<td>Capital social</td>
							<td><? echo $row['capital_social']; ?></td>
						</tr>
						<tr>
							<td>Cont</td>
							<td><? echo $row['cont']; ?></td>
						</tr>
						<tr>
							<td>Banca</td>
							<td><? echo $row['banca']; ?></td>
						</tr>
					
				</table>
			</div>
			<div id="right">
				<table>
						<tr>
							<td>Cumparator</td>
							<td><? echo $row['cumparator']; ?></td>
						</tr>
						<tr>
							<td>Nr.ord.r.c.</td>
							<td><? echo $row['cump_nr_ord_rc']; ?></td>
						</tr>
						<tr>
							<td>Cod fiscal</td>
							<td><? echo $row['cump_cod_fiscal']; ?></td>
						</tr>
						<tr>
							<td>Sediul</td>
							<td><? echo $row['cump_sediu']; ?></td>
						</tr>
						<tr>
							<td>Cont</td>
							<td><? echo $row['cump_cont']; ?></td>
						</tr>
						<tr>
							<td>Banca</td>
							<td><? echo $row['cump_banca']; ?></td>
						</tr>
				</table>
			</div>
	
		</div>
		
		<div id="facturaTabelProd">
			<table id="prodTbl">
				<tr id="tabelFactProdCap">
					<td width="30px">Nr. <br> Crt.</td>
					<td width="400px">Denumire</td>
					<td width="30px">U.M.</td>
					<td width="80px">Cantitate</td>
					<td width="80px">Pret Unitar<br> -RON-</td>
					<td width="80px">Valoare<br> -RON-</td>
					<td width="80px">Valoare TVA<br> -RON-</td>
				</tr>
				<?
						$id_comanda = $row['id_comanda'];
						$manopera = mysql_query("select * from comenzi_reparatii  where id_comanda ='$id_comanda' ");
						$rnum = 0;
						$pret_manopera = array();
						$pret_manopera_valoareTva = array();
						while($rman = mysql_fetch_array($manopera)):
						$rnum++;
						
				?>
				<tr id="tableAllprod">
					<td width="30px"><? echo $rnum; ?></td>
					<td width="260px"><? echo $rman['descriere'];?></td>
					<td width="30px">ora</td>
					<td width="60px"><? echo $rman['cant'];?></td>
					<td width="130px"><? echo $rman['tarif'];?></td>
					<td width="100px"><? echo $rman['tarif'] * $rman['cant'] * $rman['norma']; $pret_manopera[] = $rman['tarif'] * $rman['cant'] * $rman['norma']?></td>
					<td width="100px" style="border-right:2px solid #000;"><? echo ($rman['tarif'] * $rman['cant'] * $rman['norma'] )  - (faraTVA($rman['tarif']) * $rman['cant'] * $rman['norma'] );    $pret_manopera_valoareTva[] = ($rman['tarif'] * $rman['cant'] * $rman['norma'] )  - (faraTVA($rman['tarif']) * $rman['cant'] * $rman['norma'] )        ?></td>
				</tr>
				<? endwhile; ?>
				
				
					<?
						$id_comanda = $row['id_comanda'];
						$materiale = mysql_query("select * from comenzi_materiale,comenzi_materiale_relatii where comenzi_materiale_relatii.id_comanda = '$id_comanda' and comenzi_materiale_relatii.id_material =  comenzi_materiale.id_material ");
						$pret_materiale = array();
						$pret_materiale_valTVA = array();
						while($rman = mysql_fetch_array($materiale)):
						$rnum++;
						
				?>
				<tr id="tableAllprod">
					<td width="30px"><? echo $rnum; ?></td>
					<td width="260px"><? echo $rman['denumire'];?></td>
					<td width="30px">buc</td>
					<td width="60px"><? echo $rman['cant'];?></td>
					<td width="130px"><? echo $rman['pret'];?></td>
					<td width="100px"><? echo $rman['pret'] * $rman['cant']; $pret_materiale[] =  $rman['pret'] * $rman['cant']; ?></td>
					<td width="100px" style="border-right:2px solid #000;"><? echo ($rman['pret'] * $rman['cant'])  - (faraTVA($rman['pret']) * $rman['cant'] ); $pret_materiale_valTVA[] = ($rman['pret'] * $rman['cant'])  - (faraTVA($rman['pret']) * $rman['cant'] );?></td>
				</tr>
				<? endwhile; ?>
				
				
				
				
				<tr id="tableAllprod">
					<td width="30px"></td>
					<td width="260px" style="text-align:left;padding:4px;"></td>
					<td width="30px"></td>
					<td width="60px"></td>
					<td width="130px"></td>
					<td width="100px"></td>
					<td width="100px" style="border-right:2px solid #000;"></td>
				</tr>
				
				<tr id="tableAllprod">
					<td width="30px"></td>
					<td width="260px" style="text-align:left;padding:4px;"></td>
					<td width="30px"></td>
					<td width="60px"></td>
					<td width="130px"></td>
					<td width="100px"></td>
					<td width="100px" style="border-right:2px solid #000;"></td>
				</tr>
				
				<tr id="tableAllprod">
					<td width="30px"></td>
					<td width="260px" style="text-align:left;padding:4px;">Termen de plata: 7 zile</td>
					<td width="30px"></td>
					<td width="60px"></td>
					<td width="130px"></td>
					<td width="100px"></td>
					<td width="100px" style="border-right:2px solid #000;"></td>
				</tr>
					<tr id="tableAllprod">
					<td width="30px"></td>
					<td width="260px" style="text-align:left;padding:4px;">Pret negociat si acceptat conform facturii. temei legal hg206/1993.</td>
					<td width="30px"></td>
					<td width="60px"></td>
					<td width="130px"></td>
					<td width="100px"></td>
					<td width="100px" style="border-right:2px solid #000;"></td>
				</tr>
				
				
				
				
			</table>
		</div>
		
		<div id="infoFacturaRestall">
			<div id="stampila">
				Semnatura si
stampila
furnizorului
			</div>
			<div id="infoexp">
				<div id="datePersFact">
					Fact. de&nbsp;TANASE IULIAN COSTIN&nbsp;&nbsp;RR 373844&nbsp;&nbsp;CNP&nbsp;1830702460027
				</div>
				
				<div id="dateexpeditia">
					<p>Date Privind expeditia</p>
					<p>Nume Delegat</p>
					<p><div style="width:100px;float:left;margin-left:2px">B.I./C.I seria: </div><div style="width:100px;float:left;">Nr: </div></p>
					<div style="clear:both"></div>
				<p><div style="width:100px;float:left;margin-left:2px">Mijlocul de transport</div><div style="width:100px;float:left;">AUTOVEHICOL </div><div style="width:100px;float:left;">Nr: &nbsp;</div></p>
				<div style="clear:both"></div>
					<p>Expedierea s-a efectuat in prezenta noastra la data de</p>
					<p>&nbsp;&nbsp;&nbsp;&nbsp; Ora&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;Semnaturile</p>
				</div>
				
			
			</div>
			
			<div id="total" >
					<div id="totaltext">
						Total
					</div>
					
					<div id="totaltext2">
						<?
							echo array_sum($pret_materiale) + array_sum($pret_manopera) ;
						?>
					</div>
					
					<div id="totaltext2">
						<?
							echo array_sum($pret_materiale_valTVA) + array_sum($pret_manopera_valoareTva) ;
						?>
					</div>
					
			</div>
			
			<div id="semnaturaTotal">
				<div id="semnaturaPrimire">
					Semnatura de primire
				</div>
				<div id="totaldepalata">
					<b>Total de plata</b><br/>
					<b style="font-size:18px;"><?	echo array_sum($pret_materiale) + array_sum($pret_manopera) ;?></b>
				</div>
				
			</div>
				
				
				
			
			
		</div>
		
		
		
		
		
		
		
		
		
		
		
		
		
			

	</body>
	
</html>